package com.company.cloud.common.bean;

import cn.hutool.core.util.StrUtil;
import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
public class LoginSimpleUserInfo {

    private String NullDefVal = "-";

    /**
     * 用户ID
     */
    private Integer id;

    /**
     * 公司编号
     */
    private String companyNo;

    /**
     * 用户一级分类
     */
    private String userTypeOne;

    /**
     * 用户二级分类
     */
    private String userTypeTwo;

    /**
     * 用户名
     */
    private String userName;

    /**
     * IP
     */
    private String ip;

    /**
     * token
     */
    private String token;

    /**
     * 第三方ID
     */
    private Integer thirdId;

    /**
     * 第三方用户ID
     */
    private Integer thirdUserId;

    /**
     * 第三方用户标识
     */
    private String thirdOpenId;

    /**
     * 推荐人编号
     */
    private String referralCode;

    /**
     * 推荐人用户ID
     */
    private Integer referralUserId;

    /**
     * 分享码
     */
    private String shareCode;

    /**
     * apikey
     */
    private String key;

    public LoginSimpleUserInfo() {

    }

    public LoginSimpleUserInfo(String val) {
        String[] vals = val.split("\\|");
        this.id = this.toInt(vals[0]);
        this.companyNo = this.toStr(vals[1]);
        this.userName = this.toStr(vals[2]);
        this.userTypeOne = this.toStr(vals[3]);
        this.userTypeTwo = this.toStr(vals[4]);
        this.thirdId = this.toInt(vals[5]);
        this.thirdUserId = this.toInt(vals[6]);
        this.thirdOpenId = this.toStr(vals[7]);
        this.ip = this.toStr(vals[8]);
        this.token = this.toStr(vals[9]);
        this.referralCode = this.toStr(vals[10]);
        this.referralUserId = this.toInt(vals[11]);
        this.shareCode = this.toStr(vals[12]);
        this.key = this.toStr(vals[13]);
    }

    private Integer toInt(String val) {
        if (StrUtil.isEmpty(val)) {
            return null;
        } else if (this.NullDefVal.equals(val)) {
            return null;
        }
        return Integer.parseInt(val);
    }

    private String toStr(String val) {
        if (StrUtil.isEmpty(val)) {
            return null;
        } else if (this.NullDefVal.equals(val)) {
            return null;
        }
        return val;
    }

    private String v(String val) {
        if (val == null || "".equals(val)) {
            return this.NullDefVal;
        } else {
            return val;
        }
    }

    private String v(Integer val) {
        if (val == null) {
            return this.NullDefVal;
        } else {
            return val.toString();
        }
    }


    @Override
    public String toString() {
        return StrUtil.format("{}|{}|{}|{}|{}|{}|{}|{}|{}|{}|{}|{}|{}|{}",
                this.v(this.id),
                this.v(this.companyNo),
                this.v(this.userName),
                this.v(this.userTypeOne),
                this.v(this.userTypeTwo),
                this.v(this.thirdId),
                this.v(this.thirdUserId),
                this.v(this.thirdOpenId),
                this.v(this.ip),
                this.v(this.token),
                this.v(this.referralCode),
                this.v(this.referralUserId),
                this.v(this.shareCode),
                this.v(this.key)
        );

    }

    public static void main(String[] args) {
        LoginSimpleUserInfo u = new LoginSimpleUserInfo();
        u.setId(1);
        u.setCompanyNo("");
        u.setUserTypeOne("11");
        u.setUserTypeTwo("22");
        u.setUserName("anros");
        u.setThirdId(100);
        u.setThirdUserId(1);
        u.setThirdOpenId("sfsjlfsjfslfjsdfslfsdlfkjs");
        u.setIp("127.0.0.1");
        u.setToken("d090ioijslfjfsd");

        String s1 = u.toString();

        LoginSimpleUserInfo u2 = new LoginSimpleUserInfo(s1);

    }
}
